package com.dwf.dominion;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class RuleSets extends ListActivity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setListAdapter(new ArrayAdapter<String>(this, R.layout.rule_set_item,
				createRuleSetList()));

		ListView lv = getListView();
		lv.setTextFilterEnabled(true);

		lv.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {

				String name = ((TextView) view).getText().toString();
				Bundle bundle = new Bundle();
				bundle.putString("name", name);
				Intent intent = new Intent();
				intent.putExtras(bundle);
				setResult(RESULT_OK, intent);
				finish();
			}

		});

		lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

					public boolean onItemLongClick(AdapterView<?> av, View v,
							int pos, long id) {
						Toast.makeText(getApplicationContext(),
								"Long Click: " + ((TextView) v).getText(),
								Toast.LENGTH_SHORT).show();
						return true;
					}
				});
	}

	private String[] createRuleSetList() {
		return new String[] { "Lunch Group", "No attack", "Big Money" };
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.rule_set_list_menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle item selection
		switch (item.getItemId()) {
		case R.id.new_rule_set:			
			//TODO: need to create a real rule entry activity here
			Intent rulesIntent = new Intent(this,ActivityRuleEntry.class);
			startActivity(rulesIntent);
			break;
		default:
			break;
		}
		
		return super.onOptionsItemSelected(item);
	}
}
